<?php
/*
 * @Description  : 代理利润
 * @Author       : https://github.com/skyselang
 * @Date         : 2020-05-05
 * @LastEditTime : 2020-12-25
 */

namespace app\store\service;

use app\store\model\DermemberProfitBill as ModelDermemberProfitBill;

class DermemberProfitBill
{

    private static function map($param): array
    {
        $where = [];
        if ($param['user_id'] ?? '') {
            $where[] = ['user_id', '=', $param['user_id']];
        }
        if ($param['order_no'] ?? '') {
            $where[] = ['order_no', '=', $param['order_no']];
        }
        if (($param['betweenTime'] ?? []) && ($param['betweenTime'][0] ?? []) && ($param['betweenTime'][1] ?? [])) {
            $where[] = ['create_time', '>=', $param['betweenTime'][0] . ' 00:00:00'];
            $where[] = ['create_time', '<=', $param['betweenTime'][1] . ' 23:59:59'];
        }
        return $where;
    }

    /**
     * 代理利润列表
     * @param array $key
     * @return array
     */
    public static function getList(array $param)
    {
        $limit = $param['limit'];
        $page  = $param['page'];
        $where = self::map($param);
        return ModelDermemberProfitBill::getList($where, $limit, $page);
    }
}
